package com.ruoyi.web.controller.bj;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.bj.ProductList;
import com.ruoyi.system.dto.ProductListDTO;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.bj.IProductListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 产品详情管理Controller
 * 
 * @author ruoyi
 * @date 2024-12-24
 */
@RestController
@RequestMapping("/bjlist/list")
public class ProductListController extends BaseController
{
    @Autowired
    private IProductListService productListService;

    @Autowired
    private ISysDictDataService sysDictDataService;

    /**
     * 查询产品详情管理列表
     */
    @PreAuthorize("@ss.hasPermi('bj:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductList productList)
    {
        startPage();
        List<ProductList> list = productListService.selectProductListList(productList);
        return getDataTable(list,null);
    }

    /**
     * 导出产品详情管理列表
     */
    @PreAuthorize("@ss.hasPermi('bj:list:export')")
    @Log(title = "产品详情管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductList productList)
    {
        List<ProductList> list = productListService.selectProductListList(productList);
        ExcelUtil<ProductList> util = new ExcelUtil<ProductList>(ProductList.class);
        util.exportExcel(response, list, "产品详情管理数据");
    }

    /**
     * 获取产品详情管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bj:list:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productListService.selectProductListById(id));
    }

    /**
     * 新增产品详情管理
     */
    @PreAuthorize("@ss.hasPermi('bj:list:add')")
    @Log(title = "产品详情管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductList productList)
    {
        return toAjax(productListService.insertProductList(productList));
    }

    /**
     * 修改产品详情管理
     */
    @PreAuthorize("@ss.hasPermi('bj:list:edit')")
    @Log(title = "产品详情管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductList productList)
    {
        return toAjax(productListService.updateProductList(productList));
    }

    /**
     * 删除产品详情管理
     */
    @PreAuthorize("@ss.hasPermi('bj:list:remove')")
    @Log(title = "产品详情管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productListService.deleteProductListByIds(ids));
    }

    /**
     * 不分页
     */
    @GetMapping("noPage")
    public List<ProductList> noPage(){
        List<ProductList> productLists = productListService.selectProductListList(new ProductList());
        return productLists;
    }

    /**
     * 获取报价的bj_product_type类型的字典数据
     */
    @GetMapping("bjDict")
    public List<SysDictData> getDictDataList(SysDictData dictData){
        List<SysDictData> sysDictData = sysDictDataService.selectDictDataList(dictData);
        return sysDictData;
    }

    /**
     * 首页获取大图
     */
    @GetMapping("getProductList")
    public List<ProductListDTO> getProductList(@RequestParam("prType") Long prType,
                                               @RequestParam(name = "id",required = false) Long id){
        Map<String,Object> map=new HashMap<>();
        map.put("prType",prType);
        map.put("id",id);
        List<ProductListDTO> productListDTOS = productListService.selectProductList(map);
        return productListDTOS;
    }

}
